﻿using MethodTimer;
using System.Reflection;
using System;
using Serilog;
using log4net;
using log4net.Config;

namespace PrintTimeDemo
{
    internal class Program
    {
        private static readonly ILog log = LogManager.GetLogger(typeof(Program));
        static void Main(string[] args)
        {
            // 初始化 log4net
            XmlConfigurator.Configure(new FileInfo("App.config"));

            MyClass myClass = new MyClass();
            myClass.MyMethod1();
            myClass.MyMethod2();
            Console.WriteLine("Hello, World!");
            //var type = typeof(MyClass);
            //MethodInfo[] methods = type.GetMethods(BindingFlags.Public | BindingFlags.Instance);

            //foreach (var method in methods)
            //{
            //    var attributes = method.GetCustomAttributes(typeof(TimeAttribute), false);
            //    if (attributes.Length > 0)
            //    {
            //        Console.WriteLine($"Method {method.Name} has Time attribute.");
            //    }
            //}
            Console.ReadKey();
        }


    }

    public class MyClass
    {
        [Time]
        public void MyMethod1()
        {
            // 方法逻辑
            Thread.Sleep(1000);
        }

        public void MyMethod2()
        {
            // 方法逻辑
        }
    }

    //[AttributeUsage(AttributeTargets.Method)]
    //public class TimeAttribute : Attribute
    //{
    //    // 可以在这里添加属性和方法
    //}

    public static class MethodTimeLogger
    {
        //按时段输出
        //public static void Log(MethodBase methodBase, TimeSpan elapsed, string message)
        //{
        //    Console.WriteLine($"方法：{methodBase.Name} 耗时(时段)：{elapsed}, 信息：{message}");
        //}

        //按总毫秒数输出
        public static void Log(MethodBase methodBase, long milliseconds, string message)
        {
            Console.WriteLine($"方法：{methodBase.Name} 耗时(总毫秒数)：{milliseconds}, 信息：{message}");
        }
    }
}
